package net.oschina.app.ui.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;

import net.oschina.app.R;
import net.oschina.app.util.UIUtils;

/**
 * Created by YL on 2017/4/6.
 */
public class PhoneDialog extends Dialog implements
        android.view.View.OnClickListener {

    private PhoneDialog(Context context, boolean flag,
                        OnCancelListener listener) {
        super(context, flag, listener);
    }

    @SuppressLint("InflateParams")
    private PhoneDialog(Context context, int defStyle) {
        super(context, defStyle);

    }

    public PhoneDialog(Context context) {
        this(context, R.style.dialog_bottom);
    }

    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);

        View view = getLayoutInflater().inflate(R.layout.dialog_phone_style, null);
        view.findViewById(R.id.tv_quick_text).setOnClickListener(this);
        view.findViewById(R.id.tv_quick_album).setOnClickListener(this);
        view.findViewById(R.id.tv_quick_phone).setOnClickListener(this);
        view.findViewById(R.id.ib_quick).setOnClickListener(this);
        getWindow().setGravity(Gravity.BOTTOM);

        setContentView(view);

        WindowManager m = getWindow().getWindowManager();
        Display d = m.getDefaultDisplay();
        WindowManager.LayoutParams p = getWindow().getAttributes();
        p.width = d.getWidth();
        getWindow().setAttributes(p);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_quick_text:
                Toast.makeText(UIUtils.getContext(), "点击了文字", Toast.LENGTH_SHORT).show();
                break;
            case R.id.tv_quick_album:
                Toast.makeText(UIUtils.getContext(), "点击了相册", Toast.LENGTH_SHORT).show();
                break;
            case R.id.tv_quick_phone:
                Toast.makeText(UIUtils.getContext(), "点击了拍照", Toast.LENGTH_SHORT).show();
                break;
            case R.id.ib_quick:
                dismiss();
                break;
        }
    }
}
